import React from 'react'
import store from '../../store/store'
import {incrementAction,decrementAction ,setCerementAction} from '../../store/actions/countAction';
export default function Count() {
  const {count} = store.getState().count
  const accumulationHandler = () =>{
      store.dispatch(incrementAction(1))
  }
  const subtractHandler = () =>{
    store.dispatch(decrementAction(1))
  }
  const cardinalAdd = () =>{
    if(count %2 !==0) {
      store.dispatch(incrementAction(1))
    }
  }
  const waitStay = () =>{
    store.dispatch(setCerementAction(1))
  }
  return (
    <div>
        <h1>我是Count组件，我的值是{count}</h1>
        <button onClick={accumulationHandler}>累加</button>
        <button onClick={subtractHandler}>累减</button>
        <button onClick={cardinalAdd}>为基数在加</button>
        <button onClick={waitStay}>等两秒再加</button>
    </div>
  )
}
